package cn.com.cnxfs.relaxchat;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MyDatabaseHelper extends SQLiteOpenHelper {

    MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        final String CREATE_FRIEND = "create table friend (" + //id是服务器上friend表中这一条记录的id
                "id integer primary key, " +"friend integer, " + "nickname text, "+"state integer DEFAULT 0)";
        final String CREATE_CHAT = "create table chat (" +                      //0表示没有未读消息，1表示有未读消息
                "id integer primary key autoincrement, "
                +"friend integer, " + "ctime text, " + "var text, "+"state integer)";
        db.execSQL(CREATE_CHAT);                                  //记录是收还是发消息，0发，1收
        db.execSQL(CREATE_FRIEND);
        Log.d("数据库","数据库创建完毕！");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists chat");
        db.execSQL("drop table if exists friend");
        onCreate(db);
        Log.d("数据库","数据库被重置！");
    }
}
